<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>设备信息</title>
    <link href="/layui/css/layui.css" rel="stylesheet">

</head>
<body>

<div class="layui-container">
    <div class="layui-row">
        <table class="layui-table">
            <colgroup>
                <col width="200">
                <col width="100">
                <col width="100">
                <col width="200">
                <col width="200">
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>设备号(imei)</th>
                <th>型号</th>
                <th>版本号</th>
                <th>上次时间</th>
                <th>呼号</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="dev,stat : ${devs}">
                <td th:text="${dev.imei}"></td>
                <td th:text="${dev.devtype}"></td>
                <td th:text="${dev.version}"></td>
                <td th:text="${dev.curdate}"></td>
                <td th:text="${dev.callsign + '-' + dev.ssid}"></td>
                <td >
                    <button type="button" class="layui-btn layui-bg-blue" th:data-imei="${dev.imei}" onclick="gotoconfig(event)">配置</button>
                    <button type="button" class="layui-btn layui-bg-red" th:data-imei="${dev.imei}" onclick="delconfig(event)">删除</button>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

<script src="/layui/layui.js"></script>
<script>
    // Usage
    layui.use(function(){
        var layer = layui.layer;
        // Welcome
        layer.msg('加载完毕', {icon: 6});
    });
    function gotoconfig(event){
        location.href="conf?imei=" + event.target.dataset.imei;
    }
    function delconfig(event){
        layer.confirm('是否要删除该配置？', {
            btn: ['删除', '取消'] //按钮
        }, function(){
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    var rs = eval("(" + xhr.responseText + ")");
                    if (rs.retCode === "0000") {
                        layer.msg('已删除');
                        location.reload();
                    } else {
                        layer.msg('操作失败，请刷新页面重试!', {icon: 2});
                    }
                } else {
                    if (xhr.readyState === 4) {
                        layer.msg('操作失败，请检查网络是否正常!', {icon: 2});
                    }
                }
            };
            xhr.open("POST", "/aprs4g/deldev?imei="+event.target.dataset.imei);
            xhr.send();
        }, function(){

        });
    }
</script>
</body>
</html>